package com.whq.mvc.base.juc;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch downLatch = new CountDownLatch(5);

        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                System.out.println("当前线程:" + Thread.currentThread().getName() + " 正在执行");
                try {
                    Thread.sleep(3000);
                    System.out.println("当前线程:" + Thread.currentThread().getName() + " 执行完了");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } finally {
                    downLatch.countDown();
                }

            }).start();
        }
        downLatch.await();
        System.out.println("主线程结束了---");
    }
}
